<template>
  <div class="container">
    <header class="header">
      <ul>
        <li>
          <a href="javascript:window.history.back();">
            <span class="icon">&#xe738;</span>
          </a>
        </li>
        <li>
          <h1>房源预约</h1>
        </li>
        <li></li>
      </ul>
    </header>
    <div class="top">
      <img src="images/home1.png" class="fl" />
      <div class="top-r fr">
        <h1>整租·包图软件园二期 1室1厅</h1>
        <h3>次卧A·15m2 西南</h3>
        <p>
          <span>2000</span>
          <span>元/月</span>
          <span>服务费:130元</span>
        </p>
      </div>
      <div class="clear"></div>
    </div>
    <form action method="post" @submit.prevent="yuyue">
      <section>
        <h1>
          选择预约看房时间
          <input
            class="form-control"
            type="text"
            v-model="date"
            id="date-time"
            placeholder="请选择预约日期"
          />
        </h1>
        <div id="time"></div>
        <h1>联系方式</h1>
        <div class="tel">
          <input type="text" name="tel" v-model="tel" maxlength="13" value placeholder="请输入联系方式" />
          <span>更改联系方式</span>
        </div>
        <div class="username">
          <input
            type="text"
            name="username"
            v-model="username"
            maxlength="20"
            placeholder="请填写真实姓名"
          />
        </div>
      </section>
      <footer>
        <button class="btn" type="submit">立即预约</button>
        <p>地址:包图省包图市国际采购中心包图地铁站B出口500米</p>
      </footer>
    </form>
  </div>
</template>

<script type="text/ecmascript-6">
import Rolldate from "rolldate";
export default {
  name: "appoint",
  data() {
    return {
      date: "",
      tel: "",
      username: "",
    };
  },
  components: {},
  mounted() {
    this.init();
  },
  methods: {
    // 插件调用函数
    init() {
      // let _this = this;
      new Rolldate({
        // el属性
        el: "#date-time",
        // confirm方法
        confirm: (date) => {
          console.log(date); // 2020-07-07
          if (new Date().getTime() > new Date(date).getTime()) {
            // 不能选过去的时间

            // alert("预约时间不能小于当前时间");

            // this.$toast('预约时间不能小于当前时间',{
            //     position: 'bottom', // 'bottom' | 'center',
            //     duration: '1500'
            // });

            this.$alert("预约时间不能小于当前时间", {
              title: "提示",
            });
            return false;
          }

          // 给变量date赋值
          this.date = date;
        },
      });
    },

    // 提交事件方法
    yuyue() {
      // 验证
      if (this.date.length === 0) {
        this.$toast("请选择预约日期", {
          duration: "1500",
          position: "bottom",
        });
        return;
      }
      if (!/^1[3456789]\d{9}$/.test(this.tel)) {
        this.$toast("联系方式不正确", {
          duration: "1500",
          position: "bottom",
        });
        return;
      }
      if (this.username.length === 0) {
        this.$toast("请输入真实姓名", {
          duration: "1500",
          position: "bottom",
        });
        return;
      }

      // 模拟：预约成功
      let options = {
        duration: "1500",
        position: "bottom",
      };
      this.$alert("预约成功", options)
        .then(() => {
          this.$router.push("/index");
        })
        .catch(() => {});

      // 提交数据
      /**
            this.$axios({
                method: 'post',
                url: 'abc.php', // 测试
                data:{
                    date: this.date,
                    tel: this.tel,
                    username: this.username
                },// json对象
				transformRequest: [function (data) {
                    // 这块能让数据是以表单的形式提交
                    let ret = '';
                    for (let it in data) {
                        ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&';
                    }
                    return ret;
                }],
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded'
                }
            }).then((res)=>{
                console.log(res);

            }).catch((error)=>{
                console.log(error);
            });
            **/
    },
  },
  computed: {},
  watch: {},
};
</script>

<style scoped lang="less" rel="stylesheet/less">
.header {
  margin: 0.3rem 0.3rem 0;
  height: 0.5rem;
}

.header ul {
  display: flex;
  justify-content: space-between;
}

.header ul li {
  width: 2.25rem;
  height: 0.5rem;
}

.header ul li h1 {
  font-size: 0.48rem;
  text-align: center;
}

.header ul li span {
  font-size: 0.4rem;
  line-height: 0.6rem;
  display: block;
}

.top {
  margin: 0.39rem;
  box-sizing: border-box;
  padding: 0.38rem 0.38rem 0;
  -moz-box-shadow: 0 0 10px #f3f3f3;
  -webkit-box-shadow: 0 0 10px #f3f3f3;
  box-shadow: 0 0 10px #f3f3f3;
}

.top > img {
  width: 1.96rem;
  height: 1.48rem;
  display: block;
}

.top .top-r {
  width: 3.73rem;
}

.top .top-r h1 {
  font-size: 0.4rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top .top-r h3 {
  color: #adada9;
  font-size: 0.28rem;
}

.top .top-r p {
  /* margin-top: .2rem; */
  font-size: 0.26rem;
  color: #f98642;
}

.top .top-r p span:nth-child(1) {
  font-size: 0.36rem;
  font-weight: 600;
}

.top .top-r p span:nth-child(2) {
  font-size: 0.26rem;
}

.top .top-r p span:nth-child(3) {
  color: #aeaeab;
  float: right;
  position: relative;
  top: 0.08rem;
}

section {
  margin: 0 0.35rem;
  margin-bottom: 2.3rem;
}

section h1 {
  margin: 0.2rem 0;
  font-weight: 600;
  font-size: 0.36rem;
}

/* input时间 */

.form-control {
  width: 50%;
  border: none;
  height: 0.4rem;
  font-size: 0.3rem;
  float: right;
  text-align: right;
}

/* 时间插件 */

.rolldate-container .fadeIn {
  -webkit-transform: none !important;
  transform: none !important;
}

.rolldate-container .rolldate-panel {
  position: initial !important;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 4rem !important;
  z-index: 1000;
  background: #fff;
  -webkit-transition: all 0.3s ease-in-out;
  -o-transition: all 0.3s ease-in-out;
  transition: all 0.3s ease-in-out;
  -webkit-transform: none !important;
  transform: none !important;
}

.rolldate-container .rolldate-mask {
  position: initial !important;
  width: 0 !important;
  height: 0 !important;
}

#rolldate-year {
  display: none;
}

.rolldate-btn {
  display: none;
}

.rolldate-container header {
  display: none;
}

section .tel {
  margin-top: 0.3rem;
  border-top: 0.01rem solid #f7f7f6;
  border-bottom: 0.01rem solid #f7f7f6;
  height: 0.94rem;
  line-height: 1.1rem;
}

section .tel input[type="text"] {
  border: none;
  outline: none;
  font-size: 0.32rem;
  padding-left: 0.22rem;
}

section .tel span {
  float: right;
  font-size: 0.28rem;
  color: #ff3b3d;
}

section .username {
  margin-top: 0.43rem;
  height: 0.88rem;
  background-color: #f8f8f8;
  font-size: 0.32rem;
  line-height: 1.1rem;
  color: #cfcfcf;
}

section .username input[type="text"] {
  border: none;
  outline: none;
  padding-left: 0.36rem;
  background: none;
  width: 100%;
}

footer {
  position: fixed;
  bottom: 0;
  height: 2rem;
  background-color: #fff;
  width: 100%;
  box-shadow: 0 0 0.05rem #f6f6f6;
  max-width: 7.5rem;
  margin: 0 auto;
}

footer .btn {
  margin: 0.32rem auto 0;
  display: block;
  background-color: #ff3b3d;
  font-size: 0.34rem;
  height: 1rem;
  line-height: 1.1rem;
  outline: none;
  border-radius: 3.35rem;
  width: 90%;
  color: #fff;
  text-align: center;
}

footer p {
  margin-top: 0.16rem;
  font-size: 0.26rem;
  color: #afafac;
  text-align: center;
}
</style>